/**
 * 问卷调查
 * @author zhangiang
 * @date   2016/10/26
 */

import PullRefresh from '../components/mui/PullRefresh.js';
import NoData from '../components/NoData.js';

(function (lf, r) {

    var ajax = lf.utils.ajax,
        fmt = 'yyyy-MM-dd',
        doAction = lf.bridgeJs.doAction,
        getUrlParam = lf.utils.getUrlParam,
        houseNum = '',
        RC = r.createClass;

    const QUESTIONNAIREID = getUrlParam('questionnaireId'),//详情
          TYPE = getUrlParam('type'),
          END = 'end',
          ADD = 'add';

    var Body = RC({
        getInitialState: function () {
            return ({
                list: [],
                user: [],
                companyName: '',
                itemList: [],
            })
        },
        componentWillMount: function () {
            var me = this;
            var page = this.props.page;
            lf.bridgeJs.getUser(function (user) {
                me.getHouseId(user, page);
                me.setState({
                    user: user,
                });
                lf.appJs.refresh();
            })
        },

        componentDidMount: function(){
            let btn = r.findDOMNode(this.refs.btn);//peroration
            if( TYPE !=END && TYPE !=ADD ){
                  $(btn).on('tap',()=>{
                     lf.appJs.doLocation('property-list-reply.html?questionnaireId='+QUESTIONNAIREID, '问卷调查');
                  })
            }
        },

        getHouseId: function (user, page) {
            var me = this;
            ajax({
                type: 'post',
                data: {
                    questionnaireId:QUESTIONNAIREID,
                },
                success: function (data) {
                    console.log(data)
                    this.setState({
                        list:data.data,
                    })
                }.bind(me)
            }, lf.finger.api.survey.getQuestionnaireInfo);

            ajax({
                type: 'get',
                data: {
                    projectId: user.projectId,
                },
                success: function (data) {
                    me.setState({
                        company: data.data.companyName,
                    });
                }
            },'/api/finger/project/getProject')

        },
        render: function () {
            let list = this.state.list,
                company = this.state.company,
                end = lf.utils.format(list.endDate, fmt);
            return (
                <div className="property-msg">
                    <h4 className='title'>{list.title}</h4>
                    <p className='box-text'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{list.preface}</p>
                    <div className='box-content'>
                        <p className="company">{ company || '无' }</p>
                        <p className='issue'><span>截止日期</span><span> : </span>{end}</p>
                    </div>
                        <div className='box-foot'>
                            {
                                TYPE == END ? <a href="javascript:;" className="ashes" ref='btn'>已结束</a>:TYPE == ADD ?<a href="javascript:;" className="ashes" ref='btn'>已参与</a>:<a href="javascript:;" ref='btn'>立即开始</a>
                            }
                        </div>
                </div>
            );
        }
    });

    r.render(
        <Body/>,
        document.getElementById('root'), function () {
        }
    )

})(liefeng, React)
